package bussinessService.impl;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import domain.vo.HouseVO;
import domain.vo.queryObject;
import module.Houses;
import bussinessService.housesBussinessService;

/**
 * 
* @ClassName: HousesBussinessServiceImpl
* @Description: 房屋收藏业务层实现类
* @author chenchao
* @date 2013-10-31 上午07:00:36
*
 */
public class HousesBussinessServiceImpl  implements housesBussinessService{

	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 ");
	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#deleteT(java.lang.Object)
	 */
	public void deleteT(int id) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#getAll()
	 */
	public List<HouseVO> getAll() throws SQLException {
		List<HouseVO> vos = new ArrayList<HouseVO>();
		List<Houses> results = new ArrayList<Houses>();
		
		results = housesService.getAll();
		for (Houses h : results) {
			HouseVO vo = new HouseVO();
			vo.setNumber(h.getHouseNumber());
			vo.setHouseId(Integer.toString(h.getHousesId()));
			vos.add(vo);
		}
		return vos;
	}

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#getById(java.lang.String)
	 */
	public Houses getById(String id) throws SQLException {
		// TODO Auto-generated method stub
		return housesService.getById(id);
	}

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#merageObject(java.lang.Object)
	 */
	public void merageObject(Houses houses) throws SQLException {
		if (houses.getHousesId() == 0) {
			housesService.insertObject(houses);
		} else {
			housesService.updateObject(houses);
		}
		
	}

	public int countByQueryObject(queryObject queryObject) throws SQLException {
		// TODO Auto-generated method stub
		return housesService.countByQueryObject(queryObject);
	}

	public List<HouseVO> getObjectByQueryObject(queryObject queryObject) throws SQLException {
		List<HouseVO> vos = new ArrayList<HouseVO>();
		List<Houses> results = new ArrayList<Houses>();
		
		results = housesService.getObjectByQueryObject(queryObject);
		for (Houses h : results) {
			HouseVO vo = new HouseVO();
			vo.setArea(h.getDistrictName());
			vo.setBankuai(h.getBlockName());
			vo.setDistrictId(h.getBhaId());
			vo.setBlockId(h.getBankuaiId());
			vo.setFace(h.getHouseFace());
			vo.setNumber(h.getHouseNumber());
			vo.setPrice(h.getHousePrice());
			vo.setRoom(h.getRoom());
			vo.setTing(h.getTing());
			vo.setWei(h.getWei());
			vo.setWay(h.getWay());
			vo.setAreaName(h.getAreaSpecial());
			vo.setAddress(h.getHouseAddress());
			vo.setSize(h.getHouseSpecial());
			vo.setTime(sdf.format(h.getCreateTime()));
			vo.setTitle(h.getHouseTitle());
			vo.setType(h.getHouseType());
			vo.setAge(h.getHouseAge());
			vo.setBsr(h.getDataType());
			vo.setDescr(h.getHouseDecoration());
			vo.setHouseId(Integer.toString(h.getHousesId()));
			// 修要优化
			if (Houses.BUY.equals(h.getDataType())) {
				vo.setBsr("求购");
			} else if (Houses.SALE.equals(h.getDataType())) {
				vo.setBsr("出售");
			} else if (Houses.RENT.equals(h.getDataType())) {
				vo.setBsr("出租");
			} else if (Houses.FOR_RENT.equals(h.getDataType())) {
				vo.setBsr("求租");
			}
			vos.add(vo);
		}
		
		return vos;
	}

}
